package com.client.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Toolkit;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.ImageIcon;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.entity.User;
import com.util.CommonUtil;

public class TestFrame extends JFrame {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	JDesktopPane desktopPane;
	private JPanel contentPane;
	private JPanel panel;
	private User user;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					User user=new User();
					TestFrame frame = new TestFrame(user);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public TestFrame(User user) {
		this.user=user;
		setBackground(Color.LIGHT_GRAY);
		setTitle("\u6559\u52A1\u7CFB\u7EDF-\u7BA1\u7406\u5458");
		setIconImage(Toolkit.getDefaultToolkit().getImage(RoatMainFrame.class.getResource("/com/util/Logal.jpg")));
		setForeground(Color.DARK_GRAY);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(300, 100, 1440,850);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new BorderLayout(0, 0));

		
		panel = new JPanel();
		panel.setForeground(new Color(255, 255, 255));
		contentPane.add(panel, BorderLayout.CENTER);
		panel.setLayout(new BorderLayout(0, 0));
		
		
		panel.add(setMenuBar(), BorderLayout.NORTH);
		
		//panel.add(new BasicSetPanel());
		panel.add(new RoatInfoManagePanel(null));
		
		ImageIcon topIcon=new ImageIcon("src/com/util/top.jpg");
		topIcon.setImage(topIcon.getImage().getScaledInstance(this.getWidth(),120,Image.SCALE_DEFAULT));
		JLabel lblNewLabel = new JLabel();
		lblNewLabel.setLayout(null);
		lblNewLabel.setIcon(topIcon);
		contentPane.add(lblNewLabel, BorderLayout.NORTH);
		JLabel titleLabel= new JLabel("中信教务系统");
		titleLabel.setForeground(new Color(255, 215, 0));
		CommonUtil.setFont(titleLabel, 3);
		titleLabel.setBounds(520,20,400,55);
		lblNewLabel.add(titleLabel);
		
		JLabel roleLabel= new JLabel("<html><font color='white'>管理员："+user.getUserId()+",欢迎您</font></html>");
		roleLabel.setFont(new Font(null,Font.PLAIN,20));
		roleLabel.setBounds(10,80,400,25);
		lblNewLabel.add(roleLabel);
		
		final JLabel timeLabel= new JLabel();
		timeLabel.setFont(new Font(null,Font.PLAIN,16));
		timeLabel.setBounds(1240,10,200,25);
		lblNewLabel.add(timeLabel);

		 new Thread() {
		        public void run() {
		            try {
		                while (true) {
		                	timeLabel.setText(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(new Date()));//显示当前时间
		                    Thread.sleep(1000);//暂停一秒
		                }
		            } catch (Exception e) {
		            }
		        }
		    }.start();
		
		
		JLabel exitLabel= new JLabel("退出");
		exitLabel.setForeground(new Color(210, 105, 30));
		 exitLabel.setFont(new Font("Dialog", Font.PLAIN, 24));
		 exitLabel.setBounds(1200,60,60,30);
		lblNewLabel.add(exitLabel);
		
		lblNewLabel.setIcon(topIcon);
	}
	
	public JMenuBar setMenuBar(){
		JMenuBar menuBar= new JMenuBar();
		menuBar.setBackground(new Color(51,153,255));
		
		menuBar.setLayout(new GridLayout(1,4));
		menuBar.setForeground(Color.GRAY);
		
		JMenu menu = new JMenu();
		CommonUtil.setMemu(menu,"               学校管理");
		menuBar.add(menu);
		
		JMenu menu_3 = new JMenu();
		CommonUtil.setMemu(menu_3,"               信息管理");
		menuBar.add(menu_3);
		
		JMenu menu_1 = new JMenu();
		CommonUtil.setMemu(menu_1,"                教学管理");
		menuBar.add(menu_1);
		
		JMenu menu_2 = new JMenu();
		CommonUtil.setMemu(menu_2,"               活动管理");
		menuBar.add(menu_2);
		return menuBar;
	}

	


}
